const fs = require("fs");

// 数据来自 https://www.npmjs.com/package/emoticon-data
const data = JSON.parse(fs.readFileSync("./data.json"));

const titles = data.tags.map((i) => i.title);
const collection = new Map(titles.map((i) => [i, []]));
data.emoticons.forEach(({ tags, string }) => {
    tags.forEach((tag) => {
        collection.get(tag).push(string);
    });
});
fs.writeFileSync(
    "./data/data.json",
    JSON.stringify(Object.fromEntries(collection.entries()))
);
fs.writeFileSync(
    "./data/index.ts",
    `export default ${JSON.stringify(titles)} as const`
);
